package com.jy.api.dao;

import com.jy.api.domain.LeaseProduct;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * @author xiaohua
 * @data 2024/11/14 0014 18:48
 */
public interface LeaseProductDao extends JpaRepository<LeaseProduct, Integer>, JpaSpecificationExecutor<LeaseProduct> {
    List<LeaseProduct> findByStoreIdOrderByProductTypeIdDesc(String storeId);

    List<LeaseProduct> findByStoreIdOrderByQueueDesc(String storeId);
    List<LeaseProduct> findByStoreIdAndShowPcEnabledIsTrueOrderByQueueDesc(String storeId);

    @Modifying
    @Transactional
    @Query(value = "update `lease_product` SET  `product_type_name` =:productTypeName  where `product_type_id`=:productTypeId " ,nativeQuery = true)
    void updateLeaseProduct(@Param("productTypeName") String productTypeName, @Param("productTypeId")int productTypeId);
}
